package com.junxian.springboot03.juc.threadPool;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 流式计算
 */
public class StreamTest {

    //规则：id为偶数、年龄大于20、name变为大写、名称为倒叙、只输出一个用户
    public static void main(String[] args) {
        UserEntity a = new UserEntity(1L, "a", 18);
        UserEntity b = new UserEntity(2L, "b", 19);
        UserEntity c = new UserEntity(3L, "c", 20);
        UserEntity d = new UserEntity(4L, "d", 21);
        UserEntity e = new UserEntity(5L, "e", 22);
        UserEntity f = new UserEntity(6L, "f", 23);
        UserEntity g = new UserEntity(7L, "g", 24);
        List<UserEntity> list = new ArrayList<>();
        list = Arrays.asList(a, b, c, d, e, f, g);

        //链式编程、lamdba表达式、函数式接口、Stream流式计算
        list.stream()
                .filter(u->{ return u.getId()%2==0; })
                .filter(u->{ return u.getAge()>18; })
                .map(u->{ return u.getName().toUpperCase(); })
                .sorted((u1, u2)->{return  u2.compareTo(u1);})
                .limit(2)
                .forEach(System.out::println);

    }
}
